package com.bw.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bw.domain.SysBrand;
import com.bw.domain.SysGoods;
import com.bw.service.SysBrandService;
import com.bw.service.SysGoodsService;

import com.bw.utils.common.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageSerializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.util.retry.Retry;

import java.util.List;

/**
 * @author bobo棒
 * @date 2023年10月24日 16:27
 */

@RequestMapping("goods")
@RestController
public class GoodsController {
    @Autowired
    SysGoodsService sysGoodsService;
    @Autowired
    SysBrandService sysBrandService;


    /**
     * 逻辑删除
     * @param sysGoods
     * @return
     */
    @RequestMapping("delById")
    public Result delById(SysGoods sysGoods){
        sysGoods.setFlag(1);//状态该1 即不可用
        boolean b = sysGoodsService.updateById(sysGoods);
        return b?Result.success():Result.fail();

    }


    @RequestMapping("brandList")
    public Result brandList(){
        List<SysBrand> list = sysBrandService.list();
        return Result.success(list);
    }


    @RequestMapping("list")
    public Result list(@RequestBody SysGoods sysGoods, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "3") Integer pageSize){
        PageHelper.startPage(current, pageSize);
        List<SysGoods> list = sysGoodsService.list(sysGoods);
        PageInfo<SysGoods> info = new PageInfo<>(list);
        return Result.success(info);
    }
}
